﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Xml.Serialization;
using System.Threading;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
    [DataContract]
    public class HelpEntry
    {
        [DataMember]
        public string _commandTypeName;

        [DataMember]
        public string _firstWords;

        [DataMember]
        public string _example;

        [DataMember]
        public string _helpText;

        public string CommandTypeName { get { return _commandTypeName; } set { _commandTypeName = value; } }

        public string FirstWords { get { return _firstWords; } set { _firstWords = value; } }

        public string Example { get { return _example; } set { _example = value; } }

        public string HelpText { get { return _helpText; } set { _helpText = value; } }

        public static HelpEntry CreateFromCommand(Command cmd)
        {
            HelpEntry result = new HelpEntry();
            result._commandTypeName = cmd.GetType().Name;

            result._firstWords = cmd.FirstWords.BuildList(", ", (s) => s);
            result._example = string.IsNullOrEmpty(cmd.Example) ? string.Empty : cmd.Example;
            result._helpText = cmd.HelpText;

            return result;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(FirstWords + " - ");

            if (!string.IsNullOrEmpty(Example))
            {
                sb.AppendLine(HelpText);
                sb.AppendLine("  Example: " + Example);
            }
            else
            {
                sb.AppendLine(HelpText);
            }

            return sb.ToString();
        }
    }
}
